/**
 * 从字段到函数的推导
 * keyof T & string 表示string类型的属性，symbol不能进行字符串拼接
 */

type Watcher<T> = {
  on<K extends keyof T & string>(eventName: `${K}Changed`, callback: (oldValue: T[K], newValue: T[K]) => void): void;
};

declare function watch<T extends object>(obj: T): Watcher<T>;

const personWatcher = watch({
  firstName: "Xu",
  lastName: "maozeng",
  age: 28,
  sex: "男"
});

personWatcher.on("ageChanged", (oldValue, newValue) => {});
